﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using JqueryNet.FormControl;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace JqueryNet
{
    public class JQuery
    {
        public object Value { get;private set; }

        private IJQuery Ijquery { get; set; }         

        private JQuery(IJQuery query) { Ijquery = query; }

        public static JQuery Get(Control _control)
        {
            ControlFactory factory = null ;//= new ControlFactory();
            if (_control is WebControl)
                factory = new WebControlFactory();
            else if (_control is HtmlControl)
                factory = new HtmlControlFactory();
            else
                factory = new ControlFactory();            
            return new JQuery(factory.CreateIJquery(_control));
        }

        public JQuery Attr(string key)
        {
            Ijquery.Attr(key);
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Attr(string key, string value)
        {
            Ijquery.Attr(key, value);
            return this;
        }

        public JQuery Attr(object newobject)
        {
            Ijquery.Attr(newobject);
            return this;
        }

        public JQuery Attr(string key, Func<string> value)
        {
            Ijquery.Attr(key, value);
            return this;
        }

        public JQuery RemoveAttr(string key)
        {
            Ijquery.RemoveAttr(key);
            return this;
        }

        public JQuery AddClass(string cssclass)
        {
            Ijquery.AddClass(cssclass);
            return this;
        }

        public JQuery AddClass(Func<string> fun)
        {
            Ijquery.AddClass(fun);
            return this;
        }

        public JQuery RemoveClass()
        {
            Ijquery.RemoveClass();
            return this;
        }

        public JQuery ToggleClass(string cssclass)
        {
            Ijquery.ToggleClass(cssclass);
            return this;
        }

        public JQuery ToggleClass(Func<string> fun)
        {
            Ijquery.ToggleClass(fun);
            return this;
        }

        public JQuery Html()
        {
            Ijquery.Html();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Html(string value)
        {
            Ijquery.Html(value); return this;
        }

        public JQuery Html(Func<string> fun)
        {
            Ijquery.Html(fun()); return this;
        }

        public JQuery Text()
        {
            Ijquery.Text();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Text(string value)
        {
            Ijquery.Text(value);
            return this;
        }

        public JQuery Text(Func<string> fun)
        {
            Ijquery.Text(fun);
            return this;
        }

        public JQuery Val()
        {
            Ijquery.Val();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Val(string value)
        {
            Ijquery.Val(value);
            return this;
        }

        public JQuery Val(Func<string> fun)
        {
            Ijquery.Val(fun);
            return this;
        }

        public JQuery Val(string[] values)
        {
            Ijquery.Val(values);
            return this;
        }

        public JQuery Children()
        {
            Ijquery.Children();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Children<T>(Predicate<T> prc)
        {
            Ijquery.Children<T>(prc);
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Parent()
        {
            Ijquery.Parent();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Css(string key)
        {
            Ijquery.Css(key);
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Css(string key, string value)
        {
            Ijquery.Css(key, value); return this;
        }

        public JQuery Css(object newobject)
        {
            Ijquery.Css(newobject); return this;
        }

        public JQuery Css(string key, Func<string> value)
        {
            Ijquery.Css(key, value); return this;
        }

        public JQuery Height()
        {
            Ijquery.Height();
            Value = Ijquery.Value;
            return this;
        }

        public JQuery Height(string value)
        {
            Ijquery.Height(value);
            return this;
        }

        public JQuery Width()
        {
            Ijquery.Width();
            return this;
        }

        public JQuery Width(string value)
        {
            Ijquery.Width(value);
            return this;
        }

        public JQuery Bind(string key, string value)
        {
            Ijquery.Bind(key, value);
            return this;
        }

        public JQuery UnBind(string key)
        {
            Ijquery.UnBind(key);
            return this;
        }

        public JQuery Blur(string fun)
        {
            Ijquery.Blur(fun);
            return this;
        }

        public JQuery Change(string fun)
        {
            Ijquery.Change(fun);
            return this;
        }

        public JQuery Click(string fun)
        {
            Ijquery.Click(fun);
            return this;
        }

        public JQuery Dblclick(string fun)
        {
            Ijquery.Dblclick(fun);
            return this;
        }

        public JQuery Focus(string fun)
        {
            Ijquery.Focus(fun);
            return this;
        }

        public JQuery Keydown(string fun)
        {
            Ijquery.Keydown(fun);
            return this;
        }

        public JQuery Keypress(string fun)
        {
            Ijquery.Keypress(fun);
            return this;
        }

        public JQuery Keyup(string fun)
        {
            Ijquery.Keyup(fun);
            return this;
        }

        public JQuery Mousedown(string fn)
        {
            Ijquery.Mousedown(fn);
            return this;
        }

        public JQuery Mousemove(string fn)
        {
            Ijquery.Mousemove(fn);
            return this;
        }

        public JQuery Mouseout(string fn)
        {
            Ijquery.Mouseout(fn);
            return this;
        }

        public JQuery Mouseover(string fn)
        {
            Ijquery.Mouseover(fn);
            return this;
        }

        public JQuery Mouseup(string fn)
        {
            Ijquery.Mouseup(fn);
            return this;
        }

        public JQuery Select(string fn)
        {
            Ijquery.Select(fn);
            return this;
        }

        public JQuery Submit(string fun)
        {
            Ijquery.Submit(fun);
            return this;
        }
    }
}
